﻿using System.Linq;
using System.Threading.Tasks;
using cfg.card;
using cfg.character;
using cfg.pawn;
using kemocard.Scripts.Common;
using kemocard.Scripts.Module.Battle;
using kemocard.Scripts.Pawn;

namespace kemocard.Scripts.Buff;

public class SwordCollinA : BaseBuff
{
    public SwordCollinA()
    {
        Id = "SWORD_COLLIN_A";
        Name = "圣剑型科林";
        Description = "自身/2回合/物理攻击提高7500";
        Type = BuffType.BUFF;
        Duration = 2;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPAttack += 7500;
    }
}

public class SwordCollinG : BaseBuff
{
    public SwordCollinG()
    {
        Id = "SWORD_COLLIN_G";
        Name = "圣剑型科林";
        Description = "己方/全体/3回合/魔法防御提高3000,自身防御2张以上、抽卡+1";
        Type = BuffType.BUFF;
        Duration = 3;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMDefense);
        Tags.Add(BuffTag.AddDraw);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMDefense += 3000;
        if (SpecialFlag) inStruct.AddDraw += 1;
    }
}

public class SwordCollinB : BaseBuff
{
    public SwordCollinB()
    {
        Id = "SWORD_COLLIN_B";
        Name = "圣剑型科林";
        Description = "自身/3回合/魔法攻击提高7500，抽卡-1";
        Type = BuffType.BUFF;
        Duration = 3;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
        Tags.Add(BuffTag.AddDraw);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack += 7500;
        inStruct.AddDraw -= 1;
    }
}

public class SwordCollinS : BaseBuff
{
    public SwordCollinS()
    {
        Id = "SWORD_COLLIN_S";
        Name = "圣剑型科林";
        Description = "自身/3回合/治疗量提高4000";
        Type = BuffType.BUFF;
        Duration = 3;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddHeal);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddHeal += 4000;
    }
}

public class SwordRainsG : BaseBuff
{
    public SwordRainsG()
    {
        Id = "SwordRainsG";
        Name = "圣剑型雷恩斯";
        Description = "自身/2回合/嘲讽:2,反击自身物理攻击100%";
        Type = BuffType.BUFF;
        Duration = 2;
        StackNum = 1;
        StackLimit = 1;
        IsUnique = false;
        Tags.Add(BuffTag.Taunt);
        Tags.Add(BuffTag.CounterAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.Taunt += 2;
    }

    public override Task ApplyBuff(ref object data, BuffTag tag = BuffTag.None)
    {
        if (tag != BuffTag.Attacked || data is not Damage d) return Task.CompletedTask;
        var damage = new Damage()
        {
            Value = Causer.PAttack,
            Role = Causer.Role,
            Attribute = (int)Attribute.WATER,
            Tags = [Tag.WATER, Tag.PATTACK],
            Target = [d.User],
            User = Owner,
            IsFinal = true,
        };
        return Mod?.DoDamage(damage);
    }
}

public class SwordRainsB : BaseBuff
{
    public SwordRainsB()
    {
        Id = "SwordRainsB";
        Name = "圣剑型雷恩斯";
        Description = "自身/2回合/魔法攻击提高7500";
        Duration = 2;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack += 7500;
    }
}

public class OnsenTyphoonG : BaseBuff
{
    public OnsenTyphoonG()
    {
        Id = "ONSEN_TYPHOON_G";
        Name = "温泉型泰夫";
        Description = "己方/全体/3回合/物理防御提高5000,抽卡+1";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPDefense);
        Tags.Add(BuffTag.AddDraw);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPDefense += 5000;
        inStruct.AddDraw += 1;
    }
}

public class OnsenTyphoonBe : BaseBuff
{
    public OnsenTyphoonBe()
    {
        Id = "ONSEN_TYPHOON_BE";
        Name = "温泉型泰夫";
        Description = "敌方/全体/3回合/物理伤害降低5000+10%，3连携以上、自身魔法攻击提高10%";
        Duration = 3;
        Type = BuffType.DEBUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
        Tags.Add(BuffTag.ExtraPAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPAttack -= 5000;
        inStruct.ExtraPAttack -= 0.1f;
    }
}

public class OnsenTyphoonBt : BaseBuff
{
    public OnsenTyphoonBt()
    {
        Id = "ONSEN_TYPHOON_BT";
        Name = "温泉型泰夫";
        Description = "敌方/全体/3回合/物理伤害降低5000+10%，3连携以上、自身魔法攻击提高10%";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.ExtraMAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.ExtraMAttack += 0.1f;
    }
}

public class OnsenTyphoonS : BaseBuff
{
    public OnsenTyphoonS()
    {
        Id = "ONSEN_TYPHOON_S";
        Name = "温泉型泰夫";
        Description = "己方/全体/回复4000点生命值,自身回复量超过10000、己方全体1回合全攻击提高5000";
        Duration = 1;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
        Tags.Add(BuffTag.AddPAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack += 5000;
        inStruct.AddPAttack += 5000;
    }
}

public class OnsenSethB : BaseBuff
{
    public OnsenSethB()
    {
        Id = "ONSEN_SETH_B";
        Name = "温泉型赛斯";
        Description = "自身/3回合/魔法攻击提高7500+10%当前生命值，抽卡-1";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
        Tags.Add(BuffTag.AddDraw);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack += 7500 + TempValue;
        inStruct.AddDraw -= 1;
    }
}

public class OnsenSethS : BaseBuff
{
    public OnsenSethS()
    {
        Id = "ONSEN_SETH_S";
        Name = "温泉型赛斯";
        Description = "自身/2回合/回复量提高2000，己方全体回复2000点生命值";
        Type = BuffType.BUFF;
        Duration = 2;
        StackLimit = 1;
        StackNum = 1;
        Tags.Add(BuffTag.AddHeal);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddHeal += 2000;
    }
}

public class OnsenStarG : BaseBuff
{
    public OnsenStarG()
    {
        Id = "ONSEN_STAR_G";
        Name = "温泉型星";
        Description = "己方/单体/3回合/全防御提高7500，目标守护者、嘲讽：2，否则嘲讽：-2";
        Type = BuffType.BUFF;
        Duration = 3;
        StackLimit = 1;
        StackNum = 1;
        Tags.Add(BuffTag.AddMDefense);
        Tags.Add(BuffTag.Taunt);
        Tags.Add(BuffTag.AddPDefense);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMDefense += 7500;
        inStruct.AddPDefense += 7500;
        inStruct.Taunt += Owner.Role == Role.GUARD ? 2 : -2;
    }
}

public class OnsenStarB : BaseBuff
{
    public OnsenStarB()
    {
        Id = "ONSEN_STAR_B";
        Name = "温泉型星";
        Description = "敌方/全体/2回合/魔法攻击降低3000点，卡组光属性6以上、改为6000";
        Duration = 2;
        Type = BuffType.DEBUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack -= SpecialFlag ? 6000 : 3000;
    }
}

public class OnsenStarS : BaseBuff
{
    public OnsenStarS()
    {
        Id = "ONSEN_STAR_S";
        Name = "温泉型星";
        Description = "自身/2回合/回复量提高2000,自身回复量15000以上、己方全体回复2000点生命值，120%回复量适用";
        Duration = 2;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddHeal);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddHeal += 2000;
    }
}

public class OnsenRainsA : BaseBuff
{
    public OnsenRainsA()
    {
        Id = "ONSEN_RAINS_A";
        Name = "温泉型雷恩斯";
        Description = "自身/3回合/物理攻击50000以上、暴击率+100%，否则物理攻击+7500(在赋予时判断)";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
        Tags.Add(BuffTag.AddCritical);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        if (SpecialFlag)
        {
            inStruct.AddCriticalChance += 1f;
        }
        else
        {
            inStruct.AddPAttack += 7500;
        }
    }
}

public class OnsenRainsG : BaseBuff
{
    public OnsenRainsG()
    {
        Id = "ONSEN_RAINS_G";
        Name = "温泉型雷恩斯";
        Description = "己方/单体/3回合/全防御提高7500，自身防御2张以上、目标改为全体";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPDefense);
        Tags.Add(BuffTag.AddMDefense);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPDefense += 7500;
        inStruct.AddMDefense += 7500;
    }
}

public class OnsenRainsB : BaseBuff
{
    public OnsenRainsB()
    {
        Id = "ONSEN_RAINS_B";
        Name = "温泉型雷恩斯";
        Description = "敌方/单体/2回合/全攻击降低7500，自身能量50以上、改为15000";
        Type = BuffType.DEBUFF;
        Duration = 2;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
        Tags.Add(BuffTag.AddMAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPAttack -= SpecialFlag ? 15000 : 7500;
        inStruct.AddMAttack -= SpecialFlag ? 15000 : 7500;
    }
}

public class AllegoryTpA : BaseBuff
{
    public AllegoryTpA()
    {
        Id = "ALLEGORY_TP_A";
        Name = "寓言型泰夫";
        Description = "自身/2回合/物理攻击提高1000+1%生命上限，每1连携提高1%加成";
        Type = BuffType.BUFF;
        Duration = 2;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPAttack += 1000 + TempValue;
    }
}

public class AllegoryTpG : BaseBuff
{
    public AllegoryTpG()
    {
        Id = "ALLEGORY_TP_G";
        Name = "寓言型泰夫";
        Description = "己方/全体/2回合/抽卡+2";
        Type = BuffType.BUFF;
        Duration = 2;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddDraw);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddDraw += 2;
    }
}

public class AllegoryTpS : BaseBuff
{
    public AllegoryTpS()
    {
        Id = "ALLEGORY_TP_S";
        Name = "寓言型泰夫";
        Description = "自身/3回合/回复量提高1000，每回合开始时、己方全体回复1点生命";
        Type = BuffType.BUFF;
        Duration = 3;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddHeal);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddHeal += 1000;
    }

    public override Task ApplyBuff(ref object data, BuffTag tag = BuffTag.None)
    {
        if (tag != BuffTag.TurnStart || Causer is not BattleCharacter bc) return Task.CompletedTask;
        var heal = new HealStruct()
        {
            Value = 1 + bc.Heal,
            Role = Role.SUPPORT,
            Attribute = (int)Attribute.WIND,
            Target = Mod?.Teammates.ToList<BasePawn>(),
            User = Causer,
        };
        return Mod?.DoHeal(heal);
    }
}

public class AllegorySethG : BaseBuff
{
    public AllegorySethG()
    {
        Id = "ALLEGORY_SETH_G";
        Name = "寓言型赛斯";
        Description = "己方/全体/2回合/全防御提高3000,抽卡+1,消耗20能量、伤害减免+20%";
        Duration = 2;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPDefense);
        Tags.Add(BuffTag.AddMDefense);
        Tags.Add(BuffTag.AddDraw);
        Tags.Add(BuffTag.Reduction);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPDefense += 3000;
        inStruct.AddMDefense += 3000;
        inStruct.AddDraw += 1;
        if (SpecialFlag) inStruct.Reduction -= 0.2f;
    }
}

public class AllegorySethB : BaseBuff
{
    public AllegorySethB()
    {
        Id = "ALLEGORY_SETH_B";
        Name = "寓言型赛斯";
        Description = "敌方/全体/2回合/物理攻击降低3000点，卡组风属性6以上、物理防御降低3000点";
        Duration = 2;
        Type = BuffType.DEBUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
        Tags.Add(BuffTag.AddPDefense);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPAttack -= 3000;
        if (SpecialFlag) inStruct.AddPDefense -= 3000;
    }
}

public class AllegorySethS : BaseBuff
{
    public AllegorySethS()
    {
        Id = "ALLEGORY_SETH_S";
        Name = "寓言型赛斯";
        Description = "己方/单体/2回合/魔法攻击提高5000，消耗40点能量、暴击率+100%";
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
        Tags.Add(BuffTag.AddCritical);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack += 5000;
        if (SpecialFlag) inStruct.AddCriticalChance += 1f;
    }
}

public class HalloweenEllisGs : BaseBuff
{
    public HalloweenEllisGs()
    {
        Id = "HALLOWEEN_ELLIS_GS";
        Name = "万圣型埃利斯";
        Description = "自身/3回合/嘲讽:4,己方全体3回合生命上限提高30000";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.Taunt);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.Taunt += 4;
    }
}

public class HalloweenEllisGt : BaseBuff
{
    public HalloweenEllisGt()
    {
        Id = "HALLOWEEN_ELLIS_GT";
        Name = "万圣型埃利斯";
        Description = "自身/3回合/嘲讽:4,己方全体3回合生命上限提高30000";
        Duration = 3;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddHealth);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddHealth += 30000;
    }
}

public class HalloweenEllisB : BaseBuff
{
    public HalloweenEllisB()
    {
        Id = "HALLOWEEN_ELLIS_B";
        Name = "万圣型埃利斯";
        Description = "敌方/全体/3回合/全攻击降低7500+20%";
        Duration = 3;
        Type = BuffType.DEBUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddPAttack);
        Tags.Add(BuffTag.ExtraPAttack);
        Tags.Add(BuffTag.AddMAttack);
        Tags.Add(BuffTag.ExtraMAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddPAttack -= 7500;
        inStruct.AddMAttack -= 7500;
        inStruct.ExtraPAttack -= 0.2f;
        inStruct.ExtraMAttack -= 0.2f;
    }
}

public class HalloweenEllisS : BaseBuff
{
    public HalloweenEllisS()
    {
        Id = "HALLOWEEN_ELLIS_S";
        Name = "万圣型埃利斯";
        Description = "己方/全体/2回合/魔法攻击提高12500";
        Duration = 2;
        Type = BuffType.BUFF;
        StackNum = 1;
        StackLimit = 1;
        Tags.Add(BuffTag.AddMAttack);
    }

    public override void RefreshProps(ref TempPropStruct inStruct)
    {
        inStruct.AddMAttack += 12500;
    }
}